<?php

namespace App\Models;

use Dcat\Admin\Traits\HasDateTimeFormatter;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class LoopProjectLog extends Model
{
    use HasFactory,HasDateTimeFormatter;

    protected $fillable =[
        'project_id',
        'user_id',
        'status',
        'phone',
        'result',
        'cache'
    ];
    protected $casts = [
        'cache' => 'json'
    ];

    public function project(): \Illuminate\Database\Eloquent\Relations\BelongsTo
    {
        return $this->belongsTo(LoopProject::class,'project_id','id');
    }

    public function user() {
        return $this->belongsTo(User::class,'user_id','id');
    }
    public function toArray()
    {
        $arr = parent::toArray(); // TODO: Change the autogenerated stub
        if ($this->user) {
            $arr['user'] = $this->user->toArray();
            if ($this->user->parentUser)
                $arr['user']['parentUser'] = $this->user->parentUser->toArray();
        }
        return $arr;
    }
}
